"use client"
import React, { useEffect } from 'react'
import { Button, Form, Input, Select } from "antd";
import { addTableData, updateTableData } from "../Api/https";
import type { FormProps } from 'antd';

interface Iporps {
  title: string,
  itemobj: any,
  onOk: () => void,
  onCancel: () => void,
  shuju: any
}

export default function page(props: Iporps) {
  const [form] = Form.useForm();
  useEffect(() => {
    form.setFieldsValue(props.itemobj)
  }, [])

  const onFinish = (values:any) => {
    // 添加菜单功能
    values.key=values.key*1
    values.records=values.records*1
    values.price=values.price*1
    values.key=new Date().getTime()
    if (props.title == "添加") {
      // let obj = {
      //   ...values,
      // }
      addTableData(values)
      //  修改菜单功能
    } else {
      let obj = {
        ...props.itemobj,
        ...values
      }
      updateTableData(obj)
    }
    props.onOk()
    props.shuju()
  };
  return (
    <div>
      <Form
        form={form}

        onFinish={onFinish}
      >
        <Form.Item label="订单标题" name='title'
          rules={[{ required: true, message: '订单标题不能为空!' }]}
        >
          <Input placeholder='请输入订单标题' />
        </Form.Item>&emsp;

        <Form.Item label="关联客户" name='Associated_customer'
          rules={[{ required: true, message: '关联客户不能为空!' }]}
        >
          <Input placeholder='请输入关联客户' />
        </Form.Item>&emsp;

        <Form.Item label="审批状态" name='stage'
          rules={[{ required: true, message: '审批状态不能为空!' }]}
        >
          <Select placeholder='请输入审批状态'>
            <Select.Option value={true}>已提交</Select.Option>
            <Select.Option value={false}>未提交</Select.Option>
          </Select>
        </Form.Item>&emsp;

        <Form.Item label="订单总金额" name='records'
          rules={[{ required: true, message: '订单总金额不能为空!' }]}
        >
          <Input placeholder='请输入订单总金额' />
        </Form.Item>&emsp;

        <Form.Item label="已回款金额" name='price'
          rules={[{ required: true, message: '已回款金额不能为空!' }]}
        >
          <Input placeholder='请输入已回款金额' />
        </Form.Item>&emsp;
        
        <Form.Item label="已开票金额" name='keys'
          rules={[{ required: true, message: '已开票金额不能为空!' }]}
        >
          <Input placeholder='请输入已开票金额' />
        </Form.Item>&emsp;

        <Form.Item>
          <Button type='primary' htmlType='submit'>提交</Button>
        </Form.Item>&emsp;
      </Form>
    </div>
  )
}
